/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Stones;

import Actors.Actor;
import Actors.HumanControlledBall;
import Model.CollisionEvent;
import Model.OxydeEvent;
import Model.OxydeListener;
import java.awt.image.BufferedImage;
import java.util.Vector;

/**
 *
 * @author Snowangelic
 */
public class Oxyde extends AbstractSolidStone {

    Vector<OxydeListener> listeners;
    BufferedImage openImage;
    BufferedImage closedImage;

    public final int RED_OXYDE = 1;
    public final int BLUE_OXYDE = 2;
    public final int YELLOW_OXYDE = 3;
    public final int GREEN_OXYDE = 4;

    boolean open;
    boolean definitivOpen;
    int oxydeColor;

    public Oxyde(int oxydeType){
        listeners=new Vector<OxydeListener>();
        open=false;
        definitivOpen=false;
        oxydeColor=oxydeType;

        closedImage=EnigmaUtils.ImageLoader.loadImage("./images/closedOxyde.png");
        image=closedImage;

        if(oxydeType==RED_OXYDE) openImage=EnigmaUtils.ImageLoader.loadImage("./images/redOxyde.png");
        else if(oxydeType==BLUE_OXYDE) openImage=EnigmaUtils.ImageLoader.loadImage("./images/blueOxyde.png");
        else if(oxydeType==YELLOW_OXYDE) openImage=EnigmaUtils.ImageLoader.loadImage("./images/yellowOxyde.png");
        else if(oxydeType==GREEN_OXYDE) openImage=EnigmaUtils.ImageLoader.loadImage("./images/greenOxyde.png");
    }

    public void addListener(OxydeListener listener){
        if(!listeners.contains(listener))
            listeners.add(listener);
    }

    public boolean isClosed(){
        return !open;
    }
    public int getOxydeColor(){
        return this.oxydeColor;
    }

    public boolean getDefinitivOpen(){
        return definitivOpen;
    }

    public void setDefinitivOpen(boolean open){
        definitivOpen=open;
    }


    public void open(){
        if(open==false){
            open=true;
            image=openImage;
            for(OxydeListener listener : listeners)
                listener.OxydeOpened(new OxydeEvent(this));
            changed();
        }
    }
    public void close(){
       if(definitivOpen==false){
        image=closedImage;
        open=false;
        changed();
       }
    }

    @Override
    public void update(long dtime) {
    }

     public void actorCollision(CollisionEvent e){
         if(e.getActor() instanceof HumanControlledBall) open();
         super.actorCollision(e);
     }
}
